home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / HyperMail102.lha / HyperMail / libcgi / strops.c < prev    next >
C/C++ Source or Header  |  1995-06-18  |  823b  |  51 lines

  1. /*
  2.  * This file is part of the LIBCGI library
  3.  *
  4.  * Copyright 1994 by Enterprise Integration Technologies Corporation
  5.  *
  6.  * This is freeware with commercialization rights reserved; see the
  7.  * LICENSE included in the distribution for specifics.
  8.  */
  9.  
  10. #include <stdio.h>
  11.  
  12. char *trim(s)
  13.      char *s;
  14.  {
  15.   char *t=s;
  16.   
  17.   while (*t) t++;
  18.   while (t > s && *--t == ' ') *t = 0;
  19.   return s;
  20. }
  21.  
  22. char *sanitize(buf, s)
  23.      char *buf;
  24.      char *s;
  25.  {
  26.   char *t;
  27.  
  28.   for (t=buf;*s; s++)
  29.     if (*s == ' ') *t++ = '+';
  30.     else if (isalnum(*s)) *t++ = *s;
  31.     else {
  32.       sprintf(t, "%%%2X", *s);
  33.       t += 3;
  34.     }
  35.   *t = '\0';
  36.   return buf;
  37. }
  38.  
  39. char *strmaxcpy(dest, src, n)
  40.      char *dest;
  41.      char *src;
  42.      int n;
  43.  {
  44.   char *d=dest;
  45.  
  46.   if (n < 1) return NULL;
  47.   while (--n && *src) *d++ = *src++;
  48.   *d = 0;
  49.   return dest;
  50. }
  51.